/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.demo.dao.hibernate;

import com.demo.dao.AccountDao;
import com.demo.model.Account;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author dkozyrev
 */
@Repository("accountDao")
public class AccountDaoHibernate extends GenericDaoHibernate<Account, Long> implements AccountDao
{

    @Autowired
    public AccountDaoHibernate(@Qualifier("sessionFactory") SessionFactory sessionFactory)
    {
        super(Account.class);
        setSessionFactory(sessionFactory);
    }
    
    @Override
    public Account getAccountByLogin(String login) {
        List<Account> res = this.getHibernateTemplate().find(
                "from " + Account.class.getName()
                + " obj where obj.email = ?",
                login);
        if (res.isEmpty()) {
            return null;
        }

        return res.get(0);
    }

}
